package com.uniledger.exchange.bank.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.uniledger.commonlib.view.CountDownButton;
import com.uniledger.exchange.R;
import com.uniledger.exchange.bank.BankCard;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 短信验证码
 */
public class SmsCodeFragment extends CardFragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private BankCard card;
    private String mParam2;

    @BindView(R.id.btn_send_sms)
    CountDownButton countDownButton;

    @OnClick(R.id.btn_send_sms)
    void countDown() {
        countDownButton.start();
    }


    public SmsCodeFragment() {
        // Required empty public constructor
    }

    public static SmsCodeFragment newInstance(BankCard card, String param2) {
        SmsCodeFragment fragment = new SmsCodeFragment();
        Bundle args = new Bundle();
        args.putParcelable(ARG_PARAM1, card);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            card = getArguments().getParcelable(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        countDownButton.setOnCountDownFinishListener(new CountDownButton.OnCountDownFinishListener() {
            @Override
            public void onFinish() {
                //TODO 倒计时结束
            }
        });
    }

    @Override
    public int getViewResourceId() {
        return R.layout.fragment_sms_code;
    }

    @Override
    public void onClick(View v) {
        listener.success(card);
    }

    @Override
    public void onStart() {
        super.onStart();
        countDownButton.start();
    }

    @Override
    public void onStop() {
        super.onStop();
        countDownButton.stop();
    }
}
